/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.util;

import java.util.Locale;
import java.util.Map;
import javax.faces.context.FacesContext;

/**
 *
 * @author marcy
 */
public class LanguageBean {

    private Locale locale;

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }
    
    /**
     * @return
     */
    public String changeLanguage() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Map<String, String> parameters = ctx.getExternalContext().getRequestParameterMap();
        String loc = parameters.get("locale");
        if (loc != null) {
            Locale locale1 = new Locale(loc);
            ctx.getApplication().setDefaultLocale(locale1); // change the locale
            ctx.getViewRoot().setLocale(locale1);
            setLocale(locale1);
            ctx.renderResponse();
            return "ok";
        } else {
            return "missingParam";
        }
    }
}

